//
//  ReaderPageViewController.m
//  TestReader
//
//  Created by 01 on 17/2/17.
//  Copyright © 2017年 蔡正军. All rights reserved.
//

#import "ReaderPageViewController.h"
#import "DisPlayTextViewController.h"

@interface ReaderPageViewController ()

@property (nonatomic, strong) UIPageViewController *pageViewCtl;

@end

@implementation ReaderPageViewController
@synthesize pageViewCtl;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey:UIPageViewControllerOptionSpineLocationKey];
    self.pageViewCtl = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];
    
    self.pageViewCtl.dataSource = self;
    [[pageViewCtl view] setFrame:[[self view] bounds]];
    DisPlayTextViewController *textViewCtl = [self viewControllerAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObject:textViewCtl];
    
    [pageViewCtl setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
    [self addChildViewController:pageViewCtl];
    [[self view] addSubview:[pageViewCtl view]];
    [pageViewCtl didMoveToParentViewController:self];
    
    
}

- (void)setContent:(NSString *)content
{
    _content = content;
}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
      viewControllerBeforeViewController:(UIViewController *)viewController
{
    NSUInteger index = [self indexOfViewController:viewController];
    if ((index == 0) || (index == NSNotFound)) {
        return nil;
    }
    
    index--;
    return [self viewControllerAtIndex:index];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    NSUInteger index = [self indexOfViewController:viewController];
    if (index == NSNotFound) {
        return nil;
    }
    
    return  [self viewControllerAtIndex:index];
}

- (ReaderPageViewController *)viewControllerAtIndex:(NSUInteger)index
{
    ReaderPageViewController *readerPageViewCtl = [[ReaderPageViewController alloc] init];
    return readerPageViewCtl;
}

- (NSUInteger)indexOfViewController:(ReaderPageViewController *)viewController
{
    return 1;
}

         
- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.
}

    /*
     #pragma mark - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
